package br.com.dbsti.pedido;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

@Entity
@SequenceGenerator(name="SeqPedido", initialValue=1, 
        allocationSize=1, sequenceName="SEQ_PEDIDO")
@Table(name="PedidoJava")
public class Pedido implements Serializable {
    
    @Id
    @GeneratedValue(strategy= GenerationType.SEQUENCE, generator="SeqPedido")
    private Integer numero;
    @Temporal(TemporalType.DATE)
    private Date data;
    @ManyToOne(fetch= FetchType.LAZY)
    @JoinColumn(name="cliente")
    private Cliente cliente;

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof Pedido){
            Pedido p = (Pedido) obj;
            return new EqualsBuilder().append(this.numero, p.numero).isEquals();
        }
        return false;
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder().append(this.numero).toHashCode();
    }
    
    public Cliente getCliente() {
        return cliente;
    }

    public void setCliente(Cliente cliente) {
        this.cliente = cliente;
    }

    public Date getData() {
        return data;
    }

    public void setData(Date data) {
        this.data = data;
    }

    public Integer getNumero() {
        return numero;
    }

    public void setNumero(Integer numero) {
        this.numero = numero;
    }
}
